'use strict';
module.exports = () => {
  return async (ctx, next) => {
    try {
      await next();
    } catch (e) {
      // ctx.logger.error(e);
      switch (e.status) {
        case 500:
          ctx.body = {
            code: '500',
            msg: '操作失败，可能是服务器异常.',
          };
          ctx.status = 500;
          break;
        case 404:
          ctx.body = {
            code: '404',
            msg: '页面在雪地里走丢了，技术人员这就去找回来',
          };
          ctx.status = 404;
          break;
        case 422:
          ctx.body = {
            code: '422',
            msg: '参数错误',
          };
          ctx.status = 422;
          break;
        default:
          ctx.body = {
            code: '500',
            msg: '操作失败，可能是服务器异常.',
          };
          ctx.status = 500;
          break;
      }
    }
  };
};
